package com.siyoumi.app.modules.app_ess_qr.admin;

import com.siyoumi.app.entity.SysAbc;
import com.siyoumi.app.modules.app_ess_qr.service.SvcEssQr;
import com.siyoumi.app.modules.app_ess_qr.vo.VoEssQr;
import com.siyoumi.app.modules.app_fks.service.SvcFksCtiy;
import com.siyoumi.app.modules.app_fks.vo.VaFksCity;
import com.siyoumi.component.http.InputData;
import com.siyoumi.controller.AdminApiController;
import com.siyoumi.util.XReturn;
import com.siyoumi.validator.XValidator;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@RestController
@RequestMapping("/xadmin/app_ess_qr/app_ess_qr__item__edit")
public class app_ess_qr__item__edit
        extends AdminApiController {

    @GetMapping()
    public XReturn index() {
        setPageTitle("二维码-编辑");

        Map<String, Object> data = new HashMap<>();
        data.put("abc_order", 0);
        if (isAdminEdit()) {
            SysAbc entity = SvcEssQr.getApp().loadEntity(getID());

            HashMap<String, Object> dataAppend = new LinkedHashMap<>();
            dataAppend.put("id", entity.getKey());
            //
            //合并
            data = entity.toMap();
            data.putAll(dataAppend);
        }
        getR().setData("data", data);

        return getR();
    }


    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/save")
    public XReturn save(@Validated() VoEssQr vo, BindingResult result) {
        //统一验证
        XValidator.getResult(result);
        //
        vo.setAbc_acc_id(getAccId());
        vo.setAbc_table("app_ess_qr");
        //
        InputData inputData = InputData.fromRequest();
        return SvcEssQr.getBean().edit(inputData, vo);
    }
}